<?php


namespace App\Http\Controllers\Admin;
use App\Http\Controllers\BaseController;
use App\Models\Apply;
use App\Models\Banner;
use App\Models\Category;
use Illuminate\Http\Request;

class ApplyController extends BaseController
{

    /**
     * 详情
     * @param Request $request
     * @return mixed
     * @throws \Illuminate\Validation\ValidationException
     */
    public function info(Request $request) {
        $this->validate($request, [
            'id' => 'required|exists:banner'
        ]);
        $id = \request("id");
        $info = Banner::find($id);
        return $this->success($info);
    }

    /**
     * 保存|修改
     * @param Request $request
     * @return mixed
     */
    public function store(Request $request) {
        $input = $request->input();
        $id = \request("id");
        $exist_id = Apply::where('title', \request('title'))->value('id');
        if ($id) {
            if ($exist_id && ($id != $exist_id)) {
                return $this->failed("已经存在");
            }
            Category::where('id', $id)->update($input);
        } else {
            if ($exist_id)
                return $this->failed("已经存在");

            $info = Category::create($input);
            $id = $info->id;
        }
        return $this->success($id);
    }


}

